//
//  LGAddSchedulView.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/2/27.
//

#import "LGAddSchedulView.h"

#define item_W   viewPix(32)
#define line_W   (Screen_W-viewPix(90))
@interface LGAddSchedulView()

/**   */
@property (nonatomic , strong)UIView *baseView;
/**   */
@property (nonatomic , strong)UIButton *cancelBtn;
/**   */
@property (nonatomic , strong)UIButton *sureBtn;
/**   */
@property (nonatomic , strong)UILabel *titleLabel;
/**   */
@property (nonatomic , strong)UILabel *weekTitle;
/**   */
@property (nonatomic , strong)UIButton *weekBtn1;
/**   */
@property (nonatomic , strong)UIButton *weekBtn2;
/**   */
@property (nonatomic , strong)UIButton *weekBtn3;
/**   */
@property (nonatomic , strong)UIButton *weekBtn4;
/**   */
@property (nonatomic , strong)UIButton *weekBtn5;
/**   */
@property (nonatomic , strong)UIButton *weekBtn6;
/**   */
@property (nonatomic , strong)UIButton *weekBtn7;
/**   */
@property (nonatomic , strong)UILabel *timeTitle;
/**   */
@property (nonatomic , strong)UIView *timeView;
/**   */
@property (nonatomic , strong)UIButton *amButton;
/**   */
@property (nonatomic , strong)UIButton *pmButton;

/**   */
@property (nonatomic , strong)UIView *timeLineView;
/**   */
@property (nonatomic , strong)UILabel *startLabel;
/**   */
@property (nonatomic , strong)UIButton *startPoint;
/**   */
@property (nonatomic , strong)UILabel *endLabel;
/**   */
@property (nonatomic , strong)UIButton *endPoint;
/**   */
@property (nonatomic , strong)UIView *progressView;

/**   */
@property (nonatomic , strong)UILabel *numTitle;
/**   */
@property (nonatomic , strong)UIView *numberView;
/**   */
@property (nonatomic , strong)UIButton *minusBtn;
/**   */
@property (nonatomic , strong)UITextField *numberTF;
/**   */
@property (nonatomic , strong)UIButton *addBtn;
/**   */
@property (nonatomic , assign)CGFloat weekMargin;

@end

@implementation LGAddSchedulView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor colorWithString:@"#000000" alpha:0];
        self.weekMargin = (Screen_W-viewPix(54)-item_W*7)/6.0;
        [self createSubView];
        [UIView animateWithDuration:0.3 animations:^{
            self.backgroundColor = [UIColor colorWithString:@"#000000" alpha:0.5];
            self.baseView.frame = CGRectMake(0, Screen_H-viewPix(422), Screen_W, viewPix(445));
        }];
    }
    return self;
}




-(void)cancelBtnAction{
    
}

-(void)sureBtnAction{
    
}

//星期一 -- 日
-(void)weekBtnTouchAction:(UIButton *)sender{
    
}

//上午 、 下午
-(void)timeButtonTouchAction:(UIButton *)sender{
    if(sender == self.amButton){
        self.amButton.selected = YES;
        self.pmButton.selected = NO;
        
    }else{
        self.amButton.selected = NO;
        self.pmButton.selected = YES;
        
    }
}

//拖动时间条
-(void)panTimePointAction:(UIPanGestureRecognizer *)sender{
    if(sender.view == self.startPoint){
        //开始时间
        
        
    }else{
        //结束时间
    }
}

//数量 + 、 -
-(void)numberButtonAction:(UIButton *)sender{
    
}
#pragma mark
#pragma mark ====> 创建控件
-(void)createSubView{
    [self addSubview:self.baseView];
    [self.baseView addSubview:self.cancelBtn];
    [self.baseView addSubview:self.titleLabel];
    [self.baseView addSubview:self.sureBtn];
    [self.baseView addSubview:self.weekTitle];
    [self.baseView addSubview:self.weekBtn1];
    [self.baseView addSubview:self.weekBtn2];
    [self.baseView addSubview:self.weekBtn3];
    [self.baseView addSubview:self.weekBtn4];
    [self.baseView addSubview:self.weekBtn5];
    [self.baseView addSubview:self.weekBtn6];
    [self.baseView addSubview:self.weekBtn7];
    [self.baseView addSubview:self.timeTitle];
    [self.baseView addSubview:self.timeView];
    [self.timeView addSubview:self.amButton];
    [self.timeView addSubview:self.pmButton];
    [self.baseView addSubview:self.startLabel];
    [self.baseView addSubview:self.endLabel];
    [self.baseView addSubview:self.timeLineView];
    [self.timeLineView addSubview:self.progressView];
    [self.baseView addSubview:self.startPoint];
    [self.baseView addSubview:self.endPoint];
    [self.baseView addSubview:self.numTitle];
    [self.baseView addSubview:self.numberView];
    [self.numberView addSubview:self.minusBtn];
    [self.numberView addSubview:self.numberTF];
    [self.numberView addSubview:self.addBtn];
    [self.startLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.timeView.mas_bottom).offset(viewPix(10));
        make.centerX.equalTo(self.startPoint.mas_centerX);
    }];
    [self.endLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.startLabel);
        make.centerX.equalTo(self.endPoint.mas_centerX);
    }];
    [self.startPoint mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.timeLineView);
        make.centerX.equalTo(self.timeLineView.mas_left).offset(0);
        make.width.height.equalTo(@(viewPix(30)));
    }];
    [self.endPoint mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.width.height.equalTo(self.startPoint);
        make.centerX.equalTo(self.timeLineView.mas_left).offset(line_W);
    }];
    
    [self.progressView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self.timeLineView);
        make.left.equalTo(self.startPoint.mas_centerX);
        make.right.equalTo(self.endPoint.mas_centerX);
    }];
}

-(UIView *)baseView{
    if(!_baseView){
        _baseView = [[UIView alloc] initWithFrame:CGRectMake(0, Screen_H, Screen_W, viewPix(445))];
        _baseView.backgroundColor = [UIColor whiteColor];
        _baseView.cornerRidus = 15;
    }
    return _baseView;
}

-(UIButton *)cancelBtn{
    if(!_cancelBtn){
        _cancelBtn = [UIButton buttonWithTitle:@"取消" titleFont:LGFontWeight(16, UIFontWeightSemibold) textColor:@"#999999" imageName:@""];
        _cancelBtn.frame = CGRectMake(viewPix(5), viewPix(12), viewPix(60), viewPix(40));
        [_cancelBtn addTarget:self action:@selector(cancelBtnAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _cancelBtn;
}

-(UILabel *)titleLabel{
    if(!_titleLabel){
        _titleLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFontWeight(16, UIFontWeightSemibold) textAlignment:NSTextAlignmentCenter lines:1];
        _titleLabel.frame = CGRectMake(viewPix(65), viewPix(12), Screen_W-viewPix(130), viewPix(40));
    }
    return _titleLabel;
}

-(UIButton *)sureBtn{
    if(!_sureBtn){
        _sureBtn = [UIButton buttonWithTitle:@"确定" titleFont:LGFontWeight(16, UIFontWeightSemibold) textColor:@"#429BFF" imageName:@""];
        _sureBtn.frame = CGRectMake(Screen_W - 65*LGPercent, viewPix(12), 60*LGPercent, 40*LGPercent);
        [_sureBtn addTarget:self action:@selector(sureBtnAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _sureBtn;
}

-(UILabel *)weekTitle{
    if(!_weekTitle){
        _weekTitle = [UILabel lableWithText:@"星期" colorString:@"#666666" textFont:LGFontWeight(16, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
        _weekTitle.frame = CGRectMake(viewPix(24), kMaxY(self.cancelBtn.frame)+viewPix(40), viewPix(100), viewPix(22));
    }
    return _weekTitle;
}

-(UIButton *)weekBtn1{
    if(!_weekBtn1){
        _weekBtn1 = [UIButton buttonWithTitle:@"日" titleFont:LGFontWeight(14, UIFontWeightMedium) normalColor:@"#333333" selectColor:@"#FFFFFF"];
        _weekBtn1.frame = CGRectMake(viewPix(27), kMaxY(self.weekTitle.frame)+viewPix(8), item_W, item_W);
        [_weekBtn1 setBackgroundColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_weekBtn1 setBackgroundColor:[UIColor colorWithString:@"#2E9AFC"] forState:UIControlStateSelected];
        _weekBtn1.cornerRidus = item_W/2.0;
        _weekBtn1.tag = 1000+0;
        [_weekBtn1 addTarget:self action:@selector(weekBtnTouchAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _weekBtn1;
}

-(UIButton *)weekBtn2{
    if(!_weekBtn2){
        _weekBtn2 = [UIButton buttonWithTitle:@"一" titleFont:LGFontWeight(14, UIFontWeightMedium) normalColor:@"#333333" selectColor:@"#FFFFFF"];
        _weekBtn2.frame = CGRectMake(kMaxX(self.weekBtn1.frame)+self.weekMargin, kMinY(self.weekBtn1.frame), item_W, item_W);
        [_weekBtn2 setBackgroundColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_weekBtn2 setBackgroundColor:[UIColor colorWithString:@"#2E9AFC"] forState:UIControlStateSelected];
        _weekBtn2.cornerRidus = item_W/2.0;
        _weekBtn2.tag = 1000+1;
        [_weekBtn2 addTarget:self action:@selector(weekBtnTouchAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _weekBtn2;
}

-(UIButton *)weekBtn3{
    if(!_weekBtn3){
        _weekBtn3 = [UIButton buttonWithTitle:@"二" titleFont:LGFontWeight(14, UIFontWeightMedium) normalColor:@"#333333" selectColor:@"#FFFFFF"];
        _weekBtn3.frame = CGRectMake(kMaxX(self.weekBtn2.frame)+self.weekMargin, kMinY(self.weekBtn1.frame), item_W, item_W);
        [_weekBtn3 setBackgroundColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_weekBtn3 setBackgroundColor:[UIColor colorWithString:@"#2E9AFC"] forState:UIControlStateSelected];
        _weekBtn3.cornerRidus = item_W/2.0;
        _weekBtn3.tag = 1000+2;
        [_weekBtn3 addTarget:self action:@selector(weekBtnTouchAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _weekBtn3;
}

-(UIButton *)weekBtn4{
    if(!_weekBtn4){
        _weekBtn4 = [UIButton buttonWithTitle:@"三" titleFont:LGFontWeight(14, UIFontWeightMedium) normalColor:@"#333333" selectColor:@"#FFFFFF"];
        _weekBtn4.frame = CGRectMake(kMaxX(self.weekBtn3.frame)+self.weekMargin, kMinY(self.weekBtn1.frame), item_W, item_W);
        [_weekBtn4 setBackgroundColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_weekBtn4 setBackgroundColor:[UIColor colorWithString:@"#2E9AFC"] forState:UIControlStateSelected];
        _weekBtn4.cornerRidus = item_W/2.0;
        _weekBtn4.tag = 1000+3;
        [_weekBtn4 addTarget:self action:@selector(weekBtnTouchAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _weekBtn4;
}

-(UIButton *)weekBtn5{
    if(!_weekBtn5){
        _weekBtn5 = [UIButton buttonWithTitle:@"四" titleFont:LGFontWeight(14, UIFontWeightMedium) normalColor:@"#333333" selectColor:@"#FFFFFF"];
        _weekBtn5.frame = CGRectMake(kMaxX(self.weekBtn4.frame)+self.weekMargin, kMinY(self.weekBtn1.frame), item_W, item_W);
        [_weekBtn5 setBackgroundColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_weekBtn5 setBackgroundColor:[UIColor colorWithString:@"#2E9AFC"] forState:UIControlStateSelected];
        _weekBtn5.cornerRidus = item_W/2.0;
        _weekBtn5.tag = 1000+4;
        [_weekBtn5 addTarget:self action:@selector(weekBtnTouchAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _weekBtn5;
}

-(UIButton *)weekBtn6{
    if(!_weekBtn6){
        _weekBtn6 = [UIButton buttonWithTitle:@"五" titleFont:LGFontWeight(14, UIFontWeightMedium) normalColor:@"#333333" selectColor:@"#FFFFFF"];
        _weekBtn6.frame = CGRectMake(kMaxX(self.weekBtn5.frame)+self.weekMargin, kMinY(self.weekBtn1.frame), item_W, item_W);
        [_weekBtn6 setBackgroundColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_weekBtn6 setBackgroundColor:[UIColor colorWithString:@"#2E9AFC"] forState:UIControlStateSelected];
        _weekBtn6.cornerRidus = item_W/2.0;
        _weekBtn6.tag = 1000+5;
        [_weekBtn6 addTarget:self action:@selector(weekBtnTouchAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _weekBtn6;
}

-(UIButton *)weekBtn7{
    if(!_weekBtn7){
        _weekBtn7 = [UIButton buttonWithTitle:@"六" titleFont:LGFontWeight(14, UIFontWeightMedium) normalColor:@"#333333" selectColor:@"#FFFFFF"];
        _weekBtn7.frame = CGRectMake(kMaxX(self.weekBtn6.frame)+self.weekMargin, kMinY(self.weekBtn1.frame), item_W, item_W);
        [_weekBtn7 setBackgroundColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_weekBtn7 setBackgroundColor:[UIColor colorWithString:@"#2E9AFC"] forState:UIControlStateSelected];
        _weekBtn7.cornerRidus = item_W/2.0;
        _weekBtn7.tag = 1000+6;
        [_weekBtn7 addTarget:self action:@selector(weekBtnTouchAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _weekBtn7;
}

-(UILabel *)timeTitle{
    if(!_timeTitle){
        _timeTitle = [UILabel lableWithText:@"时间段" colorString:@"#666666" textFont:LGFontWeight(16, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
        _timeTitle.frame = CGRectMake(viewPix(24), kMaxY(self.weekBtn1.frame)+viewPix(28), viewPix(100), viewPix(22));
    }
    return _timeTitle;
}

-(UIView *)timeView{
    if(!_timeView){
        _timeView = [[UIView alloc]initWithFrame:CGRectMake(viewPix(24), kMaxY(self.timeTitle.frame)+viewPix(8), viewPix(164), viewPix(36))];
        _timeView.backgroundColor = [UIColor colorWithString:@"#F7F7F7"];
        _timeView.cornerRidus = viewPix(18);
    }
    return _timeView;
}

-(UIButton *)amButton{
    if(!_amButton){
        _amButton = [UIButton buttonWithTitle:@"上午" titleFont:LGFontWeight(14, UIFontWeightMedium) normalColor:@"#61616D" selectColor:@"#FFFFFF"];
        [_amButton setBackgroundColor:[UIColor colorWithString:@"#F7F7F7"] forState:UIControlStateNormal];
        [_amButton setBackgroundColor:[UIColor colorWithString:@"#3291FF"] forState:UIControlStateSelected];
        _amButton.frame = CGRectMake(0, 0, viewPix(82), viewPix(36));
        _amButton.cornerRidus = viewPix(18);
        _amButton.selected = YES;
        [_amButton addTarget:self action:@selector(timeButtonTouchAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _amButton;
}

-(UIButton *)pmButton{
    if(!_pmButton){
        _pmButton = [UIButton buttonWithTitle:@"下午" titleFont:LGFontWeight(14, UIFontWeightMedium) normalColor:@"#61616D" selectColor:@"#FFFFFF"];
        [_amButton setBackgroundColor:[UIColor colorWithString:@"#F7F7F7"] forState:UIControlStateNormal];
        [_amButton setBackgroundColor:[UIColor colorWithString:@"#3291FF"] forState:UIControlStateSelected];
        _pmButton.frame = CGRectMake(viewPix(82), 0, viewPix(82), viewPix(36));
        _pmButton.cornerRidus = viewPix(18);
        [_pmButton addTarget:self action:@selector(timeButtonTouchAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _pmButton;
}

-(UILabel *)startLabel{
    if(!_startLabel){
        _startLabel = [UILabel lableWithText:@"00:00" colorString:@"#333333" textFont:LGFontWeight(16, UIFontWeightMedium) textAlignment:NSTextAlignmentCenter lines:1];
    }
    return _startLabel;
}

-(UILabel *)endLabel{
    if(!_endLabel){
        _endLabel = [UILabel lableWithText:@"12:00" colorString:@"#333333" textFont:LGFontWeight(16, UIFontWeightMedium) textAlignment:NSTextAlignmentCenter lines:1];
    }
    return _endLabel;
}

-(UIView *)timeLineView{
    if(!_timeLineView){
        _timeLineView = [[UIView alloc]initWithFrame:CGRectMake(viewPix(45), kMaxY(self.timeView.frame)+viewPix(40), Screen_W-viewPix(90), viewPix(8))];
        _timeLineView.backgroundColor = [UIColor colorWithString:@"#EEEEEE"];
        _timeLineView.cornerRidus = viewPix(4);
    }
    return _timeLineView;
}

-(UIView *)progressView{
    if(!_progressView){
        _progressView = [[UIView alloc]init];
        _progressView.backgroundColor = [UIColor colorWithString:@"#CCE3FF"];
        _progressView.cornerRidus = viewPix(4);
    }
    return _progressView;
}

-(UIButton *)startPoint{
    if(!_startPoint){
        _startPoint = [UIButton buttonWithImage:@"添加排班-时间点" selectImage:@"添加排班-时间点"];
        [_startPoint addGestureRecognizer:[[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(panTimePointAction:)]];
    }
    return _startPoint;
}

-(UIButton *)endPoint{
    if(!_endPoint){
        _endPoint = [UIButton buttonWithImage:@"添加排班-时间点" selectImage:@"添加排班-时间点"];
        [_endPoint addGestureRecognizer:[[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(panTimePointAction:)]];
    }
    return _endPoint;
}


-(UILabel *)numTitle{
    if(!_numTitle){
        _numTitle = [UILabel lableWithText:@"每日接诊人数上限" colorString:@"#666666" textFont:LGFontWeight(16, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
        _numTitle.frame = CGRectMake(viewPix(24), kMaxY(self.timeLineView.frame)+viewPix(38), viewPix(150), viewPix(22));
    }
    return _numTitle;
}

-(UIView *)numberView{
    if(!_numberView){
        _numberView = [[UIView alloc]initWithFrame:CGRectMake(viewPix(219), kMaxY(self.timeLineView.frame)+viewPix(32), viewPix(132), viewPix(36))];
        _numberView.layer.borderColor = [UIColor colorWithString:@"#EEEEEE"].CGColor;
        _numberView.layer.borderWidth = 1;
        _numberView.cornerRidus = viewPix(18);
    }
    return _numberView;
}

-(UIButton *)minusBtn{
    if(!_minusBtn){
        _minusBtn = [UIButton buttonWithTitle:@"-" titleFont:LGFontWeight(16, UIFontWeightSemibold) textColor:@"#9595A0" imageName:@""];
        _minusBtn.layer.borderColor = [UIColor colorWithString:@"#EEEEEE"].CGColor;
        _minusBtn.layer.borderWidth = 1;
        _minusBtn.frame = CGRectMake(0, 0, viewPix(36), viewPix(36));
        [_minusBtn addTarget:self action:@selector(numberButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _minusBtn;
}

-(UIButton *)addBtn{
    if(!_addBtn){
        _addBtn = [UIButton buttonWithTitle:@"+" titleFont:LGFontWeight(16, UIFontWeightSemibold) textColor:@"#FFFFFF" imageName:@""];
        _addBtn.backgroundColor = [UIColor colorWithString:@"#3291FF"];
        _addBtn.frame = CGRectMake(viewPix(96), 0, viewPix(36), viewPix(36));
        [_addBtn addTarget:self action:@selector(numberButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _addBtn;
}

-(UITextField *)numberTF{
    if(!_numberTF){
        _numberTF = [[UITextField alloc]initWithFrame:CGRectMake(viewPix(33), 0, viewPix(66), viewPix(36))];
        _numberTF.tintColor = [UIColor colorWithString:@"#2B2A37"];
        _numberTF.textColor = [UIColor colorWithString:@"#2B2A37"];
        _numberTF.textAlignment = NSTextAlignmentCenter;
        _numberTF.keyboardType = UIKeyboardTypeNumberPad;
        _numberTF.placeholder = @"";
        _numberTF.font = LGFont(14);
    }
    return _numberTF;
}


@end
